import axios from '@/libs/axios1'
let jsonHeaders = {'content-type': 'application/json;charset=UTF-8'}

/**
 * 查询摄像头列表
 * @param {*} param0 { cameraName 摄像头名称；pageIndex 当前页； pageSize 分页大小 }
 * @returns 
 */
export const getCameraList = ({ cameraName, pageIndex, pageSize }) => {
    return axios({
		url: `/pusher/cameras`,
		method: 'get',
		params: {
            pageIndex,
            pageSize,
            cameraName
        },
		headers: jsonHeaders
	})
}

/**
 * @param {*} param0 { accessPath 访问地址；cameraName 摄像头名称； description 描述 }
 * @returns 
 */
export const addCamera = ({ accessPath, cameraName, description }) => {
    return axios({
		url: `/pusher/cameras`,
		method: 'post',
		data: {
            accessPath,
            cameraName,
            description
        },
		headers: jsonHeaders
	})
}

/**
 * 删除摄像头
 * @param {*} cameraIds 数组类型，允许批量删除
 * @returns 
 */
export const deleteCamera = (cameraIds) => {
    return axios({
		url: `/pusher/cameras`,
		method: 'delete',
		data: cameraIds,
		headers: jsonHeaders
	})
}

/**
 * 修改摄像头
 * @param {*} cameraId 指定摄像头
 * @param {*} trialCamera 修改的数据对象 { accessPath 访问地址；cameraName 摄像头名称； description 描述 }
 * @returns 
 */
export const updateCamera = (cameraId, trialCamera) => {
    return axios({
		url: `/pusher/cameras/${cameraId}`,
		method: 'put',
		data: trialCamera,
		headers: jsonHeaders
	})
}

/**
 * 分页查询指定试验任务绑定的摄像头
 * @param {*} param0 { taskId 指定试验任务；pageIndex 当前页；pageSize 分页大小；cameraName 摄像头名称； }
 * @returns 
 */
export const getBindCameraList = ({ taskId, pageIndex, pageSize, cameraName }) => {
    return axios({
		url: `/pusher/cameras/${taskId}/camera`,
		method: 'get',
		params: {
            pageIndex,
            pageSize,
			cameraName
        },
		headers: jsonHeaders
	})
}

/**
 * 绑定摄像头与试验任务的关系
 * @param {*} taskId 指定试验任务
 * @param {*} cameraIds 数组，支持批量绑定
 * @returns 
 */
export const bindCamera = (taskId, cameraIds) => {
    return axios({
		url: `/pusher/cameras/${taskId}/camera`,
		method: 'post',
		data: cameraIds,
		headers: jsonHeaders
	})
}

/**
 * 解除试验任务与摄像头的绑定关系
 * @param {*} taskId 指定试验任务
 * @param {*} ids 数组，支持批量解绑
 * @returns 
 */
export const unbindCamera = (taskId, ids) => {
    return axios({
		url: `/pusher/cameras/${taskId}/camera`,
		method: 'delete',
		data: ids,
		headers: jsonHeaders
	})
}

/**
 * 推送单个摄像头视屏流
 * @param {*} cameraId 指定摄像头
 * @param {*} operation 操作方式（start：开始；stop：停止）
 * @returns 
 */
export const pushCameraData = (cameraId, operation) => {
    return axios({
		url: `/pusher/pushManage/pushCameraSteam/${cameraId}`,
		method: 'get',
		params: {
            operation
        },
		headers: jsonHeaders
	})
}

/**
 * 根据竞赛ID推送摄像头视屏流
 * @param {*} taskId 指定竞赛
 * @param {*} operation 操作方式（start：开始；stop：停止）
 * @returns 
 */
export const pushCameraDataByTask = (taskId, operation) => {
    return axios({
		url: `/pusher/pushManage/pushCameraSteam/task/${taskId}`,
		method: 'get',
		params: {
            operation
        },
		headers: jsonHeaders
	})
}